import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:meta/meta.dart';
import 'package:portal_website/home_page.dart';
import 'package:portal_website/pages/brand_building_page.dart';
import 'package:portal_website/pages/double/double_new_page.dart';
import 'package:portal_website/pages/double_page.dart';
import 'package:portal_website/pages/leadership_care.dart';
import 'package:portal_website/pages/news.dart';
import 'package:portal_website/pages/service_capability.dart';
import 'package:portal_website/pages/three/conference_service.dart';
import 'package:portal_website/pages/three/credit_service_page.dart';
import 'package:portal_website/pages/three/insurance_page.dart';
import 'package:portal_website/pages/three/internet_marketing.dart';
import 'package:portal_website/pages/three/network_security.dart';
import 'package:portal_website/pages/three/talent_cultivation.dart';
import 'package:portal_website/pages/two/interlligent_compu_center_page.dart';
import 'package:portal_website/pages/two/knowlege_center_page.dart';
import 'package:portal_website/pages/two/model_center_page.dart';
import 'package:portal_website/pages/two/scene_applica_center_page.dart';

import 'pages/empowerment_platform.dart';

class MainController extends GetxController {
  int currentIndex = 0;

  int currentMenuIndex = -1;

  int currentSubIndex = -1;

  int currentNavIndex = 0;

  bool showRightMenu = false;
  // 政策法规、双创服务、动态资讯、企业云图、联系我们
  // 关联导航栏与PageView
  //  late PortalController _portalController;
  // ...["系统门户", "赋能平台", "新闻资讯", "领导关怀", "服务能力", "双创政策"]
  final List<NavbarItem> navbarItems = [
    NavbarItem(title: '首页', subItems: null, index: 0, page: PortalPage()),
    NavbarItem(
        title: '政策法规',
        page: EmpowermentPlatformPage(),
        subItems: [
          SubMenuItem(
            title: "模型中枢",
            index: 2,
            page: ModelCenterPage(),
          ),
          SubMenuItem(title: "知识中枢", index: 3, page: KnowledgeCenterPage()),
          SubMenuItem(
              title: "场景应用中心", index: 4, page: SceneApplicaCenterPage()),
          SubMenuItem(
              title: "智算中心", index: 5, page: InterlligentCompuCenterPage()),
          SubMenuItem(title: "互联网营销", index: 6, page: InternetMarketingPage()),
          SubMenuItem(title: "品牌建设", index: 7, page: BrandBuildingPage()),
          SubMenuItem(title: "人才培养", index: 8, page: TalentCultivationPage()),
          SubMenuItem(title: "信用服务", index: 9, page: CreditServicePage()),
          SubMenuItem(title: "金融/保险", index: 10, page: InsurancePage()),
          SubMenuItem(title: "网络安全", index: 11, page: NetworkSecurityPage()),
          SubMenuItem(title: "会务服务", index: 12, page: ConferenceServicePage()),
        ],
        index: 1),
    NavbarItem(title: '双创服务', subItems: null, index: 13, page: DoubleNewPage()),
    NavbarItem(title: '动态资讯', subItems: null, index: 14, page: NewsPage()),
    NavbarItem(
        title: '企业云图', subItems: null, index: 15, page: LeaderCarePage()),
    NavbarItem(
        title: '联系我们',
        subItems: null,
        index: 16,
        page: ServiceCapabilityPage()),
  ];

  // 定义所有内容页面（与导航项一一对应）
  List<Widget> get contentPages {
    List<Widget> tmp = [];
    navbarItems.forEach((e) {
      if (e.page is Widget) {
        tmp.add(e.page!);
      }
      e.subItems?.forEach((s) {
        if (s.page is Widget) {
          tmp.add(s.page!);
        }
      });
    });
    return tmp;
  }
}

// 导航项模型（支持二级菜单）
class NavbarItem {
  final String title;
  final List<SubMenuItem>? subItems; // 二级菜单（null表示无二级菜单）
  final int index;
  final Widget? page;
  NavbarItem({
    required this.title,
    this.page,
    required this.index,
    this.subItems,
  });
}

// 二级菜单项模型
class SubMenuItem {
  final String title;
  final int index;
  final Widget? page;
  SubMenuItem({
    required this.title,
    this.page,
    required this.index,
  });
}
